﻿using MediatR;
using WarehouseManagement.Application.Command.ShipApplyCommand;
using WarehouseManagement.Infrstructre.Interface;
namespace WarehouseManagement.Application.CommandHandler.ShipApplyCommandHandlers
{
    public class DelShipCommandHandlers:IRequestHandler<DelShipCommand,int>
    {


        private readonly IShipRequestRepository _ship;

        public DelShipCommandHandlers(IShipRequestRepository ship)
        {
            _ship = ship;
        }

        public async Task<int> Handle(DelShipCommand request, CancellationToken cancellationToken)
        {
            var res = (await _ship.GetAll()).Where(x => request.ids.Contains(x.ShippRequestAppId)).ToList();
            foreach (var item in res)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await _ship.UpdateAsync(item);
            }

            return 1;
        }
    }
}
